<?php
include "../config.php";
include "../util/functions.php";
session_start();

checkUserSession();

$action = $_REQUEST['action'];
$memberId = $_REQUEST['memberId'];
switch ($action) {
    case 'delete' : {
    } break;
    case 'moveup' : {
    } break;
    case 'movedown' : {
    } break;
}

$mylink = mySqlOpen($mySQLserver, $mySQLuser, $mySQLpassword, $mySQLdefaultdb);

$members = getMembers();

mySqlClose($mylink);

?>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="keywords" content="">
    <meta name="description" content="">
    <title>Реестр членов(<?php print count ($members); ?>)</title>
    <link href="../css/sro.css" rel="stylesheet" type="text/css">
    <script src="../js/Event.js" language="javascript"></script>
    <script src="../js/modificatMenu.js" language="javascript"></script>
    <script src="../js/resize.js" language="javascript"></script>

    <link rel="stylesheet" type="text/css" href="../css/jquery.css" media="screen">
    <script type="text/javascript" src="../js/jquery-1.js"></script>
    <script type="text/javascript" src="../js/jquery.js"></script>
    <script type="text/javascript" src="../js/jquery_002.js"></script>

    <script type="text/javascript">
        $(document).ready(function() {

            $(".member_action").each(function() {
                var memberId = $(this).children(".hidden_id").text();
                var action   = $(this).children(".hidden_act").text();
                $(this).click(function() {
                    if (action == 'delete') {
                        var answer = confirm ("Вы уверены, что хотите удалить члена СРО?");
                        if (!answer) {
                            return;
                        }
                    }
                    var form = $("#actionForm");
                    if (action == 'edit') {
                        form = $("#actionFormEdit");
                        $("#actionFormEdit input[name=memberId]").val(memberId);
                    } else {
                        $("#actionForm input[name=action]").val(action);
                        $("#actionForm input[name=memberId]").val(memberId);
                    }
                    form.submit();
                });
            });

        });
    </script>

</head>
<body>
<div id="container">
<?php
$SELECTED_MENU="menu-1";
include "banner.php"
?>
    <div class="workzone">
        <div style="height: 197px; min-height: 197px;" id="text">

            <h2 class="blueheading24">Реестр членов:</h2>
            <table class="members_tab" border="1">
                <tr>
                    <th>№</th>
                    <th>Наименование организации</th>
                    <th>Адрес</th>
                    <th>ИНН</th>
                    <th>ОГРН</th>
                    <th>Действия</th>
                </tr>
            <?php
                $cnt = 0;
                foreach ($members as $key => $member) {
                    $cnt++;
                ?>
                    <tr>
                        <td><?php print $cnt; ?></td>
                        <td><a href="?memberId=<?php print $key; ?>"><?php print $member["name"]; ?></a></td>
                        <td><?php print $member["address"]; ?></td>
                        <td><?php print $member["inn"]; ?></td>
                        <td><?php print $member["ogrn"]; ?></td>
                        <td>
                            <span class="alink member_action">
                                <span class="hidden_act">delete</span><span class="hidden_id"><?php print $key; ?></span>
                                <img src="../images/delete.png" alt="удалить члена" width="16" height="16">
                            </span>
                            <span class="alink member_action">
                                <span class="hidden_act">movedown</span><span class="hidden_id"><?php print $key; ?></span>
                                <img src="../images/movedown.png" alt="переместить члена ниже" width="16" height="16">
                            </span>
                            <span class="alink member_action">
                                <span class="hidden_act">moveup</span><span class="hidden_id"><?php print $key; ?></span>
                                <img src="../images/moveup.png" alt="переместить члена выше" width="16" height="16">
                            </span>
                            <span class="alink member_action">
                                <span class="hidden_act">edit</span><span class="hidden_id"><?php print $key; ?></span>
                                <img src="../images/edit.png" alt="редактировать члена" width="16" height="16">
                            </span>
                        </td>
                    </tr>
                <?php
                }
            ?>
            </table>

    </div>


    <div class="clear"></div>
    <div class="footer">
        <!--TODO: add footer-->
    </div>

    <div style="display:none;">
        <form id="actionForm" action="members.php" method="post">
            <input type="hidden" name="action">
            <input type="hidden" name="memberId">
        </form>
        <form id="actionFormEdit" action="member_edit.php">
            <input type="hidden" name="memberId">
        </form>
    </div>

</div>


</body>
</html>
